package fr.umlv.m2.jee.portailEtudiant.service.Impl;

import fr.umlv.m2.jee.portailEtudiant.persistence.*;
import fr.umlv.m2.jee.portailEtudiant.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: soufiane
 * Date: 19/03/11
 * Time: 22:27
 * To change this template use File | Settings | File Templates.
 */
@Service("defaultDisplayCourseService")
public class DefaultDisplayCourseService implements IDisplayCourseService {

    @Autowired
    @Qualifier("hibernateCourseDAO")
    private ICourseDAO courseDAO;

    @Override
    @Transactional(readOnly=true)
    public List<DisplayCourse> getAllDisplayCourses() {
        List< DisplayCourse > result = new ArrayList< DisplayCourse >();

        for(Course course : courseDAO.findAll()) {
            result.add(new DisplayCourse(course));
        }
        return result;
    }



    @Override
    @Transactional(readOnly=true)
    public List<DisplayTd> getAllTdsById(String id) {
        List< DisplayTd > result = new ArrayList< DisplayTd >();

        for(Td td : courseDAO.findTdsByCourseId(id)) {
            result.add(new DisplayTd(td));
        }
        return result;
    }

    @Override
    @Transactional(readOnly=true)
    public List<DisplayTp> getAllTpsById(String id) {
        List< DisplayTp > result = new ArrayList< DisplayTp >();

        for(Tp tp : courseDAO.findTpsByCourseId(id)) {
            result.add(new DisplayTp(tp));
        }
        return result;
    }

    @Override
    @Transactional(readOnly=true)
    public List<DisplayTutorial> getAllTutorialsById(String id) {
        List< DisplayTutorial > result = new ArrayList< DisplayTutorial >();

        for(Tutorial tutorial : courseDAO.findTutorialsByCourseId(id)) {
            result.add(new DisplayTutorial(tutorial));
        }
        return result;
    }

    @Override
    @Transactional(readOnly=true)
    public List<DisplayCourseDocument> getAllDocumentById(String id) {
         List<DisplayCourseDocument> result = new ArrayList<DisplayCourseDocument>();

        for(CourseDocument course : courseDAO.findDocumentByCourseId(id)) {
            result.add(new DisplayCourseDocument(course));
        }
        return result;
    }


}
